package com.edais.service.imp;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.edais.dao.ActivitySendMessageDao;
import com.edais.dao.AgreementTemplateDao;
import com.edais.dao.SystemIdWorkerDao;
import com.edais.domain.ActivitySendMessage;
import com.edais.service.SystemIdWorkerService;
import java.util.concurrent.ConcurrentHashMap;
/**
 * @author ouyy
 *
 */
@Service

public class SystemIdWorkerServiceImpl implements SystemIdWorkerService {
	private static final Log logger = LogFactory
			.getLog(SystemIdWorkerServiceImpl.class);

	@Autowired
	private SystemIdWorkerDao systemIdWorkerDao;
	@Autowired
	private AgreementTemplateDao agreementTemplateDao;

	
	@Override
	public  String getCurrentNo() throws Exception {
		// TODO Auto-generated method stub
		Map<String, Object> map = systemIdWorkerDao.getCurrentNo();
		String currNo=(String)map.get("current_date_var");
		logger.info("返回的合同编号："+currNo);
		if(StringUtils.isBlank(currNo)){
			SimpleDateFormat sm=new SimpleDateFormat("yyMMdd");
			String date=sm.format(new Date());
			currNo="000"+date+"00000001" ;
		}
		return currNo;
	}
	

		@Override
		public Map<String, String> getAgreementContext(String agreementNo) throws Exception {
			// TODO Auto-generated method stub
			return agreementTemplateDao.getAgreementContext(agreementNo);
		}


		@Override
		public String getAutoLoanId(String idType) throws Exception {
			// TODO Auto-generated method stub
			Map<String, Object> map = systemIdWorkerDao.getAutoLoanId();
			String currNo=(String)map.get("current_date_var");
			logger.info("返回的上标借款ID："+currNo);
			if(StringUtils.isBlank(currNo)){
				SimpleDateFormat sm=new SimpleDateFormat("yyMMdd");
				String date=sm.format(new Date());
				currNo=date+"00000001" ;
			}
			return currNo;
		}

}
